package sv.gob.mh.dgii.dao.corr;

import java.sql.SQLException;
import org.springframework.stereotype.Repository;
import sv.gob.mh.dgii.dao.hibernate.HibernateDaoNoCrudImpl;

@Repository
public class CorrUtilsDaoImpl extends HibernateDaoNoCrudImpl implements CorrUtilsDao{

	public boolean contribuyenteGanaMenos50mil(String nit,String periodoAnterior){		
		String sql = "{ ? = call PKG_CORR_UTILS.isless50(?, ?) }";
		Object[] params = { new Long(0), nit, periodoAnterior};
		Long res = 0L;
		try {
			res = (Long)executeFunction(sql, params);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}	
		if(res==1)return true;		
		return false;
	}
	
	public Long bloqueaContribuyenteCorrelativos(String nit, String usuario){
		String function = "{ ? = call PKG_CORR_BLOQUEO.fn_invoca_bloqueo(?,?) }";
		Long indice = null;		
		Object[] params = new Object[]{new Long(0),nit, usuario};
		try {
			indice = (Long)executeFunction(function, params);			
		} catch (Exception e) {	
			e.printStackTrace();
			throw new RuntimeException(e);
		}		
		return indice;
	}
		
	public String folioCorrelativosWeb(){
		String function = "{ ? = call PKG_CORR_UTILS.get_siguiente_folio_corr_web() }";
		String folio = "";		
		Object[] params = new Object[]{new String()};
		try {
			Object res = executeFunction(function, params);
			folio = res.toString();
		} catch (Exception e) {			
			throw new RuntimeException(e);
		}		
		return folio;		
	}
	
	
	public String cambioDeCartera(String nit){
		String function = "{ ? = call PKG_CORR_UTILS.f_contri_cambiara_cartera(?) }";
		String respuesta = "";		
		Object[] params = new Object[]{new String(),nit};
		try {
			Object res = executeFunction(function, params);
			respuesta = res.toString();
		} catch (Exception e) {			
			throw new RuntimeException(e);
		}		
		return respuesta;		
	}
	
}
